<?php
/**
 * 消息提示类
 * @author bing.peng
 *
 */
class Message {
	
	var $_messages = array();
	
	function Message($params = array()) {
    	if (count($params) > 0) {
   			$this->init($params);
  		}
	}
	
	function init($params = array()) {
		if (count($params) > 0) {   
    		foreach ($params as $key => $val) {
      			$this->$key = $val;
      		}        
    	}
	}
	
	/**
	 * 设置消息
	 * 域名默认为空，如果为空则自动添加数组下标
	 * @param $prompt string 提示消息
	 * @param $field string 域名
	 * @return void
	 */
	function set($message, $field = '') {
		if($field == '') {
			array_push($this->_messages, $message);
		}
		else {
			$this->_messages[$field] = $message;
		}
	}
	
	/**
	 * 根据域名获取提示消息
	 * @param $field string 域名
	 * @return string
	 */
	function get($field) {
		if(isset($this->_messages[$field])) {
			return $this->_messages[$field];
		}
		return "";
	}
	
	/**
	 * 获取所有提示消息
	 * @return string
	 */
	function all() {
		if( count($this->_messages) > 0 ) {
			$messages_string = "<ul>";
			foreach($this->_messages as $message) {
				$messages_string .= "<li>". $message ."</li>";
			}	
			return $messages_string . "</ul>";
		}
		return "";
	}
	
}
?>